<?php
/* Author: tbloc@cantho.gov.vn */
class Thu_ban_com{  
//Properties
private $THU_ID;
private $XUAT_ID;
private $SO_TIEN;
//properties set get 
public function setTHU_ID($THU_ID) 
{
	$this->THU_ID = $THU_ID;
}
public function getTHU_ID()
{
	return $this->THU_ID;
}	        
public function setXUAT_ID($XUAT_ID) 
{
	$this->XUAT_ID = $XUAT_ID;
}
public function getXUAT_ID()
{
	return $this->XUAT_ID;
}	        
public function setSO_TIEN($SO_TIEN) 
{
	$this->SO_TIEN = $SO_TIEN;
}
public function getSO_TIEN()
{
	return $this->SO_TIEN;
}	        
//crud methods
public function insert($db = null) {
	if ($db != null){
	$sql = "INSERT INTO `thu_ban_com`(                        
			`THU_ID`, 
				`XUAT_ID`, 
				`SO_TIEN`, 
		)
	VALUES(
    		:THU_ID, 
	    		:XUAT_ID, 
	    		:SO_TIEN, 
	    );";
	$parameters = array(
			":THU_ID", 
				":XUAT_ID", 
				":SO_TIEN", 
		);
    $values = array(  
    		$this->getTHU_ID(), 
	    		$this->getXUAT_ID(), 
	    		$this->getSO_TIEN(), 
	    );
    $types = array(
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    );
	$lastInsertID = $db->executeNonQuery($sql, $parameters, $values, $types, true);
	$this->setXUAT_ID($lastInsertID);
    }
}
	
	public function delete($db = null) {
	    if ($db != null) {
	        $sql = "delete FROM `thu_ban_com`
	                where `XUAT_ID` = :XUAT_ID;";
	        $parameters = array(":XUAT_ID");
	        $values = array($this->getXUAT_ID());
	        $types = array(PDO::PARAM_INT);//Kiem tra lai kieu du lieu nhe
	        $result = $db->executeNonQuery($sql, $parameters, $values, $types);
	        return $result;
	    }
	}
	
	public function update($db = null) {
	        if ($db != null) {
	            $sql = "UPDATE `thu_ban_com` SET 
			`THU_ID`=:THU_ID,
				`XUAT_ID`=:XUAT_ID,
				`SO_TIEN`=:SO_TIEN,
			WHERE `XUAT_ID` = :XUAT_ID;";
	            $parameters = array(
			":THU_ID",
				":XUAT_ID",
				":SO_TIEN",
			);
	// Kiem tra dau , nhe
	$values = array(  
			$this->getTHU_ID(),
				$this->getXUAT_ID(),
				$this->getSO_TIEN(),
		);
    $types = array(
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    );
	$result = $db->executeNonQuery($sql, $parameters, $values, $types);
	return $result;
	        }
	 }
	 
	public function getByID($db = null) {
	if ($db != null) {
	$sql = "SELECT
			`THU_ID`,
				`XUAT_ID`,
				`SO_TIEN`,
			FROM `thu_ban_com` WHERE `XUAT_ID` = :XUAT_ID and `is_active`=1;";
	$parameters = array(":XUAT_ID");
	$values = array($this->getXUAT_ID());
	$types = array(PDO::PARAM_INT);//kiem tra lai kieu du lieu nhe
	$rows = $db->executeQuery($sql, $parameters, $values, $types);
	if ($rows != null) {
	$row = $rows->fetch();
		$this->setTHU_ID($row->THU_ID);
		$this->setXUAT_ID($row->XUAT_ID);
		$this->setSO_TIEN($row->SO_TIEN);
	}
	return $this;
		}
	}
	
	public function getList($db = null) {
	if ($db != null) {
    $sql = "SELECT
			`THU_ID`,
				`XUAT_ID`,
				`SO_TIEN`,
			FROM `thu_ban_com` WHERE `is_active`=1;";
    $rows = $db->executeQuery($sql);
    $objects = array();
    if ($rows != null) {
    while ($row = $rows->fetch()) {
    $obj = new thu_ban_com();
    	 $obj->setTHU_ID($row->THU_ID);
		 $obj->setXUAT_ID($row->XUAT_ID);
		 $obj->setSO_TIEN($row->SO_TIEN);
		$objects[] = $obj;
    }
    return $objects;
    }
        }
    }
}
?>

